package Model;

import com.sun.org.apache.xpath.internal.operations.Mod;
import utils.Lock;

// 单例的Model层，全局唯一线程安全，用于 存储数据 + 处理复杂逻辑
public class Model {
    Integer state;//当前应用程序的“状态”（也可以理解为数据）
    String Text;

    private static Model instance = new Model();

    public static Model getInstance() {
        return instance;
    }

    private Model(){
        state = 0;
        Text = "初始Model文字";
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        synchronized (Lock.getStateLock()){
            this.state = state;
        }
    }

    public String getText() {
        return Text;
    }

    public void setText(String text) {
        System.out.println("setText");
        synchronized (Lock.getTextLock()){
            Text = text;
        }
    }

    void stateSwitcher(){
        if(state<=1)//state可取0，1，2
            state++;
        else
            state=0;
    }
}